package cn.com.ninng;

import java.util.*;

/**
 * 两数之和
 * @author ninng
 */
public class Problem1 {

    public static void main(String[] args) {
        int[] a = new int[]{2,7,11,15};
        int[] ints = twoSum(a, 9);
        System.out.println();
    }


    /**
     *
     * @param nums
     * @param target
     * @return
     */
    public static int[] twoSum(int[] nums, int target) {
        int[] result = new int[2];
        ArrayList<Integer> numList = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            int b = numList.indexOf(target - nums[i]);
            if (b>=0){
                result[0] = b;
                result[1] = i;
                return result;
            }
            numList.add(nums[i]);
        }
        return null;
    }
}
